﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using Passageways;
using Passageways.DataAccess;
using Passageways.Logs;
using Passageways.Settings;
using Passageways.WebControls;
using Passageways.DirectoryServices.UserDirectory;

namespace Yahtzee.Islands
{
    public partial class Yahtzee : PWIslandContext
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
            }
            else
            {
                int runningcount = 0;
                Session["runningcount"] = runningcount;

                int subtotal = 0;
                Session["subtotal"] = subtotal;

                int topsection = 0;
                Session["topsection"] = topsection;

                int runningScore = 0;
                Session["runningScore"] = runningScore;
                LScoreing.Text = "";

                int startroll = 0;
                Session["RollNumber"] = startroll;
                LRollNumber.Text = Session["RollNumber"].ToString();

                int YahtzeeCount = 0;
                Session["YahtzeeCount"] = YahtzeeCount;
            }
        }

        protected void IBRoll_Click(object sender, ImageClickEventArgs e)
        {
            Random GenRandNum = new Random();

            int rollcount = Convert.ToInt32(Session["RollNumber"]);
            rollcount = rollcount + 1;
            Session["RollNumber"] = rollcount;
            LFeedback.Text = "Roll " + rollcount.ToString();
            //LRollNumber.Text = rollcount.ToString();

            if (rollcount == 3)
            {
                LFeedback.Text = "Select a score";
                IBRoll.Enabled = false;
            }

            if (rollcount < 4)
            {
                if (CBOne.Checked == true)
                {
                }
                else
                {
                    HFone.Value = "";
                    LOne.Text = "";
                    int o = GenRandNum.Next(1, 7);
                    string im = "";
                    if (o == 1)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/1die.png' alt='" + o + "'>";
                    }
                    if (o == 2)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/2die.png' alt='" + o + "'>";
                    }
                    if (o == 3)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/3die.png' alt='" + o + "'>";
                    }
                    if (o == 4)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/4die.png' alt='" + o + "'>";
                    }
                    if (o == 5)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/5die.png' alt='" + o + "'>";
                    }
                    if (o == 6)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/6die.png' alt='" + o + "'>";
                    }
                    LOne.Text = im;
                    HFone.Value = o.ToString();
                }
                if (CBTwo.Checked == true)
                {
                }
                else
                {
                    HFtwo.Value = "";
                    LTwo.Text = "";
                    int o = GenRandNum.Next(1, 7);
                    string im = "";
                    if (o == 1)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/1die.png' alt='" + o + "'>";
                    }
                    if (o == 2)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/2die.png' alt='" + o + "'>";
                    }
                    if (o == 3)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/3die.png' alt='" + o + "'>";
                    }
                    if (o == 4)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/4die.png' alt='" + o + "'>";
                    }
                    if (o == 5)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/5die.png' alt='" + o + "'>";
                    }
                    if (o == 6)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/6die.png' alt='" + o + "'>";
                    }
                    LTwo.Text = im;
                    HFtwo.Value = o.ToString();
                }
                if (CBThree.Checked == true)
                {
                }
                else
                {
                    HFthree.Value = "";
                    LThree.Text = "";
                    int o = GenRandNum.Next(1, 7);
                    string im = "";
                    if (o == 1)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/1die.png' alt='" + o + "'>";
                    }
                    if (o == 2)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/2die.png' alt='" + o + "'>";
                    }
                    if (o == 3)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/3die.png' alt='" + o + "'>";
                    }
                    if (o == 4)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/4die.png' alt='" + o + "'>";
                    }
                    if (o == 5)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/5die.png' alt='" + o + "'>";
                    }
                    if (o == 6)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/6die.png' alt='" + o + "'>";
                    }
                    LThree.Text = im;
                    HFthree.Value = o.ToString(); ;
                }
                if (CBFour.Checked == true)
                {
                }
                else
                {
                    HFfour.Value = "";
                    LFour.Text = "";
                    int o = GenRandNum.Next(1, 7);
                    string im = "";
                    if (o == 1)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/1die.png' alt='" + o + "'>";
                    }
                    if (o == 2)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/2die.png' alt='" + o + "'>";
                    }
                    if (o == 3)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/3die.png' alt='" + o + "'>";
                    }
                    if (o == 4)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/4die.png' alt='" + o + "'>";
                    }
                    if (o == 5)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/5die.png' alt='" + o + "'>";
                    }
                    if (o == 6)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/6die.png' alt='" + o + "'>";
                    }
                    LFour.Text = im;
                    HFfour.Value = o.ToString(); ;
                }
                if (CBFive.Checked == true)
                {
                }
                else
                {
                    HFfive.Value = "";
                    LFive.Text = "";
                    int o = GenRandNum.Next(1, 7);
                    string im = "";
                    if (o == 1)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/1die.png' alt='" + o + "'>";
                    }
                    if (o == 2)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/2die.png' alt='" + o + "'>";
                    }
                    if (o == 3)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/3die.png' alt='" + o + "'>";
                    }
                    if (o == 4)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/4die.png' alt='" + o + "'>";
                    }
                    if (o == 5)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/5die.png' alt='" + o + "'>";
                    }
                    if (o == 6)
                    {
                        im = "<img src='../../Modules/Yahtzee/Images/6die.png' alt='" + o + "'>";
                    }
                    LFive.Text = im;
                    HFfive.Value = o.ToString(); ;
                }
            }
        }
        protected void ResetRoll()
        {
            IBRoll.Enabled = true;
            Session["RollNumber"] = 0;
            LFeedback.Text = "";
            LOne.Text = "";
            LTwo.Text = "";
            LThree.Text = "";
            LFour.Text = "";
            LFive.Text = "";
            HFone.Value = "";
            HFtwo.Value = "";
            HFthree.Value = "";
            HFfour.Value = "";
            HFfive.Value = "";
            CBOne.Checked = false;
            CBTwo.Checked = false;
            CBThree.Checked = false;
            CBFour.Checked = false;
            CBFive.Checked = false;
        }
        protected int[] GetRollValues()
        {
            //int valuetest = Convert.ToInt32(HFone.Value);
            int valueOne = Convert.ToInt32(HFone.Value);
            int valueTwo = Convert.ToInt32(HFtwo.Value);
            int valueThree = Convert.ToInt32(HFthree.Value);
            int valueFour = Convert.ToInt32(HFfour.Value);
            int valueFive = Convert.ToInt32(HFfive.Value);

            int[] RollValues = {valueOne, valueTwo, valueThree, valueFour, valueFive};

            return RollValues;
        }
        protected void SumAllDice()
        {
            int addall = 0;
            foreach (int num in GetRollValues())
            {
                addall += num;
            }
            int scoreing = Convert.ToInt32(Session["runningScore"]);
            scoreing += addall;
            Session["runningScore"] = scoreing;
            LScoreing.Text = scoreing.ToString();
        }
        protected void zeroScore()
        {
            int scoreing = Convert.ToInt32(Session["runningScore"]);
            scoreing += 0;
            Session["runningScore"] = scoreing;
            LScoreing.Text = scoreing.ToString();
        }
        protected void RunningCount()
        {
            int rc = Convert.ToInt32(Session["runningcount"]);
            if (rc == 12)
            {
                LFeedback.Text = "Game Over";
                IBRoll.Enabled = false;
                PEnd.Visible = true;
            }
            else
            {
                rc++;
                Session["runningcount"] = rc;
            }
        }
        protected void IBSubmitScore_Click(object sender, ImageClickEventArgs e)
        {
            PWUser currentUser = PWSession.CurrentUser;
            string userID = currentUser.ID;
            string UserEmail = currentUser.EMail;
            string userFullName = currentUser.FirstName;

            //string userFullName = currentUser.FirstName + " " + currentUser.LastName;
            //SqlConnection myConnection = new SqlConnection(Module.ConnectionString);
            SqlCommand myCmd = new SqlCommand();
            myCmd.Connection = new SqlConnection(Module.ConnectionString);
            myCmd.CommandText = "INSERT into HighScore (userid, Name, Gameid, Score) Values (@userid, @Name, @Gameid, @Score)";
            myCmd.Parameters.Add("@userid", SqlDbType.NVarChar).Value = userID;
            myCmd.Parameters.Add("@Name", SqlDbType.NVarChar).Value = userFullName;
            myCmd.Parameters.Add("@Gameid", SqlDbType.NVarChar).Value = "Y001";
            myCmd.Parameters.Add("@Score", SqlDbType.Int).Value = Convert.ToInt32(Session["runningScore"]);
            myCmd.Connection.Open();
            myCmd.ExecuteNonQuery();
            myCmd.Connection.Close();

            // LDone.Text = "Score Submitted";
            PEnd.Visible = false;
        }
        protected void IBHighScore_Click(object sender, ImageClickEventArgs e)
        {
            if (PScores.Visible == false)
            {
                PScores.Visible = true;
                string query = "SELECT TOP(5)Name, Score FROM HighScore ORDER BY Score DESC";
                SqlDataReader drHigh = PWDatabase.ExecuteReader(Module.ConnectionString, CommandType.Text, query, null);
                GVHighScores.DataSource = drHigh;
                GVHighScores.DataBind();
            }
            else
            {
                PScores.Visible = false;
            }
        }
        public string[] RemoveDups(string[] items, bool sort)
        {
            ArrayList noDups = new ArrayList();
            for (int i = 0; i < items.Length; i++)
            {
                if (!noDups.Contains(items[i].Trim()))
                {
                    noDups.Add(items[i].Trim());
                }
            }
            if (sort) noDups.Sort();  //sorts list alphabetically
            string[] uniqueItems = new String[noDups.Count];
            noDups.CopyTo(uniqueItems);
            return uniqueItems;
        }
        //One
        protected void IB1_Click(object sender, ImageClickEventArgs e)
        {
            if (HFone.Value != "")
            {
                int addones = 0;
                foreach (int num in GetRollValues())
                {
                    if (num == 1)
                    {
                        addones += num;
                    }
                }
                int scoreing = Convert.ToInt32(Session["runningScore"]);
                int subtotal = Convert.ToInt32(Session["subtotal"]);
                int topsection = Convert.ToInt32(Session["topsection"]);
                topsection += 1;
                subtotal += addones;
                Session["topsection"] = topsection;
                Session["subtotal"] = subtotal;
                string bonus = "";
                if (topsection == 6)
                {
                    if (subtotal >= 63)
                    {
                        scoreing += 35;
                        bonus = "<br>+ 35 Bonus";
                    }
                }
                //LRollNumber.Text = topsection.ToString();
                LSubTotal.Text = subtotal.ToString() + bonus;

                scoreing += addones;
                Session["runningScore"] = scoreing;
                LScoreing.Text = scoreing.ToString();
                IB1.Attributes.Remove("src");
                IB1.Attributes.Add("src", "../../Modules/Yahtzee/Images/1d.jpg");
                IB1.Enabled = false;
                ResetRoll();
                RunningCount();
            }
        }
        //Two
        protected void IB2_Click(object sender, ImageClickEventArgs e)
        {
            if (HFone.Value != "")
            {
                int addtwos = 0;
                foreach (int num in GetRollValues())
                {
                    if (num == 2)
                    {
                        addtwos += num;
                    }
                }
                int scoreing = Convert.ToInt32(Session["runningScore"]);
                int subtotal = Convert.ToInt32(Session["subtotal"]);
                int topsection = Convert.ToInt32(Session["topsection"]);
                topsection += 1;
                subtotal += addtwos;
                Session["topsection"] = topsection;
                Session["subtotal"] = subtotal;
                string bonus = "";
                if (topsection == 6)
                {
                    if (subtotal >= 63)
                    {
                        scoreing += 35;
                        bonus = "<br>+ 35 Bonus";
                    }
                }
                //LRollNumber.Text = topsection.ToString();
                LSubTotal.Text = subtotal.ToString() + bonus;

                scoreing += addtwos;
                Session["runningScore"] = scoreing;
                LScoreing.Text = scoreing.ToString();
                IB2.Attributes.Remove("src");
                IB2.Attributes.Add("src", "../../Modules/Yahtzee/Images/2d.jpg");
                IB2.Enabled = false;
                ResetRoll();
                RunningCount();
            }
        }
        //Three
        protected void IB3_Click(object sender, ImageClickEventArgs e)
        {
            if (HFone.Value != "")
            {
                int addthrees = 0;
                foreach (int num in GetRollValues())
                {
                    if (num == 3)
                    {
                        addthrees += num;
                    }
                }
                int scoreing = Convert.ToInt32(Session["runningScore"]);
                int subtotal = Convert.ToInt32(Session["subtotal"]);
                int topsection = Convert.ToInt32(Session["topsection"]);
                topsection += 1;
                subtotal += addthrees;
                Session["topsection"] = topsection;
                Session["subtotal"] = subtotal;
                string bonus = "";
                if (topsection == 6)
                {
                    if (subtotal >= 63)
                    {
                        scoreing += 35;
                        bonus = "<br>+ 35 Bonus";
                    }
                }
                //LRollNumber.Text = topsection.ToString();
                LSubTotal.Text = subtotal.ToString() + bonus;

                scoreing += addthrees;
                Session["runningScore"] = scoreing;
                LScoreing.Text = scoreing.ToString();
                IB3.Attributes.Remove("src");
                IB3.Attributes.Add("src", "../../Modules/Yahtzee/Images/3d.jpg");
                IB3.Enabled = false;
                ResetRoll();
                RunningCount();
            }
        }
        //Four
        protected void IB4_Click(object sender, ImageClickEventArgs e)
        {
            if (HFone.Value != "")
            {
                int addfours = 0;
                foreach (int num in GetRollValues())
                {
                    if (num == 4)
                    {
                        addfours += num;
                    }
                }
                int scoreing = Convert.ToInt32(Session["runningScore"]);
                int subtotal = Convert.ToInt32(Session["subtotal"]);
                int topsection = Convert.ToInt32(Session["topsection"]);
                topsection += 1;
                subtotal += addfours;
                Session["topsection"] = topsection;
                Session["subtotal"] = subtotal;
                string bonus = "";
                if (topsection == 6)
                {
                    if (subtotal >= 63)
                    {
                        scoreing += 35;
                        bonus = "<br>+ 35 Bonus";
                    }
                }
                //LRollNumber.Text = topsection.ToString();
                LSubTotal.Text = subtotal.ToString() + bonus;

                scoreing += addfours;
                Session["runningScore"] = scoreing;
                LScoreing.Text = scoreing.ToString();
                IB4.Attributes.Remove("src");
                IB4.Attributes.Add("src", "../../Modules/Yahtzee/Images/4d.jpg");
                IB4.Enabled = false;
                ResetRoll();
                RunningCount();
            }
        }
        //Five
        protected void IB5_Click(object sender, ImageClickEventArgs e)
        {
            if (HFone.Value != "")
            {
                int addfives = 0;
                foreach (int num in GetRollValues())
                {
                    if (num == 5)
                    {
                        addfives += num;
                    }
                }
                int scoreing = Convert.ToInt32(Session["runningScore"]);
                int subtotal = Convert.ToInt32(Session["subtotal"]);
                int topsection = Convert.ToInt32(Session["topsection"]);
                topsection += 1;
                subtotal += addfives;
                Session["topsection"] = topsection;
                Session["subtotal"] = subtotal;
                string bonus = "";
                if (topsection == 6)
                {
                    if (subtotal >= 63)
                    {
                        scoreing += 35;
                        bonus = "<br>+ 35 Bonus";
                    }
                }
                //LRollNumber.Text = topsection.ToString();
                LSubTotal.Text = subtotal.ToString() + bonus;
                scoreing += addfives;
                Session["runningScore"] = scoreing;
                LScoreing.Text = scoreing.ToString();
                IB5.Attributes.Remove("src");
                IB5.Attributes.Add("src", "../../Modules/Yahtzee/Images/5d.jpg");
                IB5.Enabled = false;
                ResetRoll();
                RunningCount();
            }
        }
        //Six
        protected void IB6_Click(object sender, ImageClickEventArgs e)
        {
            if (HFone.Value != "")
            {
                int addsixes = 0;
                foreach (int num in GetRollValues())
                {
                    if (num == 6)
                    {
                        addsixes += num;
                    }
                }
                int scoreing = Convert.ToInt32(Session["runningScore"]);
                int subtotal = Convert.ToInt32(Session["subtotal"]);
                int topsection = Convert.ToInt32(Session["topsection"]);
                topsection += 1;
                subtotal += addsixes;
                Session["topsection"] = topsection;
                Session["subtotal"] = subtotal;
                string bonus = "";
                if (topsection == 6)
                {
                    if (subtotal >= 63)
                    {
                        scoreing += 35;
                        bonus = "<br>+ 35 Bonus";
                    }
                }
                //LRollNumber.Text = topsection.ToString();
                LSubTotal.Text = subtotal.ToString() + bonus;

                scoreing += addsixes;
                Session["runningScore"] = scoreing;
                LScoreing.Text = scoreing.ToString();
                IB6.Attributes.Remove("src");
                IB6.Attributes.Add("src", "../../Modules/Yahtzee/Images/6d.jpg");
                IB6.Enabled = false;
                ResetRoll();
                RunningCount();
            }
        }
        //Kind 3
        protected void IBKind3_Click(object sender, ImageClickEventArgs e)
        {
            if (HFone.Value != "")
            {
                int ychecker1 = 0;
                int ychecker2 = 0;
                int ychecker3 = 0;
                int ychecker4 = 0;
                int ychecker5 = 0;
                int ychecker6 = 0;
                int go = 0;

                foreach (int num in GetRollValues())
                {
                    if (num == 1)
                    {
                        ychecker1 += 1;
                    }
                    if (num == 2)
                    {
                        ychecker2 += 1;
                    }
                    if (num == 3)
                    {
                        ychecker3 += 1;
                    }
                    if (num == 4)
                    {
                        ychecker4 += 1;
                    }
                    if (num == 5)
                    {
                        ychecker5 += 1;
                    }
                    if (num == 6)
                    {
                        ychecker6 += 1;
                    }
                }
                int[] YValues = {ychecker1, ychecker2, ychecker3, ychecker4, ychecker5, ychecker6 };
                foreach (int number in YValues)
                {
                    if (number >= 3)
                    {
                        go = 1;
                    }
                }
                if (go == 1)
                {
                    SumAllDice();
                }
                else
                {
                    zeroScore();
                }
                IBKind3.Attributes.Remove("src");
                IBKind3.Attributes.Add("src", "../../Modules/Yahtzee/Images/3kindd.jpg");
                IBKind3.Enabled = false;
                ResetRoll();
                RunningCount();
            }
        }
        //Kind 4
        protected void IBKind4_Click(object sender, ImageClickEventArgs e)
        {
            if (HFone.Value != "")
            {
                int ychecker1 = 0;
                int ychecker2 = 0;
                int ychecker3 = 0;
                int ychecker4 = 0;
                int ychecker5 = 0;
                int ychecker6 = 0;
                int go = 0;

                foreach (int num in GetRollValues())
                {
                    if (num == 1)
                    {
                        ychecker1 += 1;
                    }
                    if (num == 2)
                    {
                        ychecker2 += 1;
                    }
                    if (num == 3)
                    {
                        ychecker3 += 1;
                    }
                    if (num == 4)
                    {
                        ychecker4 += 1;
                    }
                    if (num == 5)
                    {
                        ychecker5 += 1;
                    }
                    if (num == 6)
                    {
                        ychecker6 += 1;
                    }
                }
                int[] YValues = {ychecker1, ychecker2, ychecker3, ychecker4, ychecker5, ychecker6 };
                foreach (int number in YValues)
                {
                    if (number >= 4)
                    {
                        go = 1;
                    }
                }
                if (go == 1)
                {
                    SumAllDice();
                }
                else
                {
                    zeroScore();
                }
                IBKind4.Attributes.Remove("src");
                IBKind4.Attributes.Add("src", "../../Modules/Yahtzee/Images/4kindd.jpg");
                IBKind4.Enabled = false;
                ResetRoll();
                RunningCount();
            }
        }
        //Full House
        protected void IBFullHouse_Click(object sender, ImageClickEventArgs e)
        {
            if (HFone.Value != "")
            {
                int ychecker1 = 0;
                int ychecker2 = 0;
                int ychecker3 = 0;
                int ychecker4 = 0;
                int ychecker5 = 0;
                int ychecker6 = 0;
                foreach (int num in GetRollValues())
                {
                    if (num == 1)
                    {
                        ychecker1++;
                    }
                    if (num == 2)
                    {
                        ychecker2++;
                    }
                    if (num == 3)
                    {
                        ychecker3++;
                    }
                    if (num == 4)
                    {
                        ychecker4++;
                    }
                    if (num == 5)
                    {
                        ychecker5++;
                    }
                    if (num == 6)
                    {
                        ychecker6++;
                    }
                }
                int[] YValues = {ychecker1, ychecker2, ychecker3, ychecker4, ychecker5, ychecker6 };

                bool fp = false;
                bool sp = false;
                foreach (int number in YValues)
                {
                    if (number == 3)
                    {
                        fp = true;
                    }
                }
                if (fp == true)
                {
                    foreach (int number in YValues)
                    {
                        if (number == 2)
                        {
                            sp = true;
                        }
                    }
                }

                int scoreing = Convert.ToInt32(Session["runningScore"]);
                if ((fp == true) && (sp == true))
                {
                    scoreing += 25;
                }
                else
                {
                    scoreing += 0;
                }

                Session["runningScore"] = scoreing;
                LScoreing.Text = scoreing.ToString();
                IBFullHouse.Attributes.Remove("src");
                IBFullHouse.Attributes.Add("src", "../../Modules/Yahtzee/Images/fullhoused.jpg");
                IBFullHouse.Enabled = false;
                ResetRoll();
                RunningCount();
            }
        }
        //S Straight
        protected void IBSS_Click(object sender, ImageClickEventArgs e)
        {
            if (HFone.Value != "")
            {
                string valueOne = HFone.Value;
                string valueTwo = HFtwo.Value;
                string valueThree = HFthree.Value;
                string valueFour = HFfour.Value;
                string valueFive = HFfive.Value;
                string[] RollValuesString = new string[5] { valueOne, valueTwo, valueThree, valueFour, valueFive };

                string[] uniqueItems = RemoveDups(RollValuesString, true);

                string[] sOne = new string[4] { "1", "2", "3", "4" };
                string[] sTwo = new string[4] { "2", "3", "4", "5" };
                string[] sThree = new string[4] { "3", "4", "5", "6" };

                string[] sfour = new string[5] { "2", "3", "4", "5", "6" };
                string[] sfive = new string[5] { "1", "2", "3", "4", "5" };
                string[] ssix = new string[5] { "1", "3", "4", "5", "6" };
                string[] sseven = new string[5] { "1", "2", "3", "4", "6" };

                int ss1 = 0;
                int ss2 = 0;
                int ss3 = 0;
                int ss4 = 0;
                int ss5 = 0;
                int ss6 = 0;
                int ss7 = 0;
                int go = 0;
                if (uniqueItems.Length == 4)
                {
                    for (int i = 0; i < uniqueItems.Length; i++)
                    {
                        if (uniqueItems[i] == sOne[i])
                        {
                            ss1++;
                        }
                        if (uniqueItems[i] == sTwo[i])
                        {
                            ss2++;
                        }
                        if (uniqueItems[i] == sThree[i])
                        {
                            ss3++;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < uniqueItems.Length; i++)
                    {
                        if (uniqueItems[i] == sfour[i])
                        {
                            ss4++;
                        }
                        if (uniqueItems[i] == sfive[i])
                        {
                            ss5++;
                        }
                        if (uniqueItems[i] == ssix[i])
                        {
                            ss6++;
                        }
                        if (uniqueItems[i] == sseven[i])
                        {
                            ss7++;
                        }
                    }
                }
                if ((ss1 == 4) || (ss2 == 4) || (ss3 == 4) || (ss4 == 5) || (ss5 == 5) || (ss6 == 5) || (ss7 == 5))
                {
                    go = 1;
                }
                int scoreing = Convert.ToInt32(Session["runningScore"]);
                if (go == 1)
                {
                    scoreing += 30;
                }
                else
                {
                    scoreing += 0;
                }

                Session["runningScore"] = scoreing;
                LScoreing.Text = scoreing.ToString();
                IBSS.Attributes.Remove("src");
                IBSS.Attributes.Add("src", "../../Modules/Yahtzee/Images/ssd.jpg");
                IBSS.Enabled = false;
                ResetRoll();
                RunningCount();
            }
        }
        //L Straight
        protected void IBLS_Click(object sender, ImageClickEventArgs e)
        {

            if (HFone.Value != "")
            {
                int valueOne = Convert.ToInt32(HFone.Value);
                int valueTwo = Convert.ToInt32(HFtwo.Value);
                int valueThree = Convert.ToInt32(HFthree.Value);
                int valueFour = Convert.ToInt32(HFfour.Value);
                int valueFive = Convert.ToInt32(HFfive.Value);

                int[] RollValues = new int[5] { valueOne, valueTwo, valueThree, valueFour, valueFive };
                Array.Sort(RollValues);
                int[] sOne = new int[5] { 1, 2, 3, 4, 5 };
                int[] sTwo = new int[5] { 2, 3, 4, 5, 6 };
                int lsvone = 0;
                int lsvtwo = 0;
                for (int i = 0; i < RollValues.Length; i++)
                {
                    if (RollValues[i] == sOne[i])
                    {
                        lsvone++;
                    }
                    if (RollValues[i] == sTwo[i])
                    {
                        lsvtwo++;
                    }
                }
                int scoreing = Convert.ToInt32(Session["runningScore"]);
                if ((lsvone == 5) || (lsvtwo == 5))
                {
                    scoreing += 40;
                }
                else
                {
                    scoreing += 0;
                }
                Session["runningScore"] = scoreing;
                LScoreing.Text = scoreing.ToString();
                IBLS.Attributes.Remove("src");
                IBLS.Attributes.Add("src", "../../Modules/Yahtzee/Images/lsd.jpg");
                IBLS.Enabled = false;
                ResetRoll();
                RunningCount();
            }
        }
        //Chance
        protected void IBChance_Click(object sender, ImageClickEventArgs e)
        {
            if (HFone.Value != "")
            {
                SumAllDice();
                IBChance.Attributes.Remove("src");
                IBChance.Attributes.Add("src", "../../Modules/Yahtzee/Images/chanced.jpg");
                IBChance.Enabled = false;
                ResetRoll();
                RunningCount();
            }
        }
        //Yahtzee
        protected void IBYahtzee_Click(object sender, ImageClickEventArgs e)
        {
            if (HFone.Value != "")
            {
                int ycount = Convert.ToInt32(Session["YahtzeeCount"]);
                int scoreing = Convert.ToInt32(Session["runningScore"]);

                int ychecker1 = 0;
                int ychecker2 = 0;
                int ychecker3 = 0;
                int ychecker4 = 0;
                int ychecker5 = 0;
                int ychecker6 = 0;
                int go = 0;

                foreach (int num in GetRollValues())
                {
                    if (num == 1)
                    {
                        ychecker1 += 1;
                    }
                    if (num == 2)
                    {
                        ychecker2 += 1;
                    }
                    if (num == 3)
                    {
                        ychecker3 += 1;
                    }
                    if (num == 4)
                    {
                        ychecker4 += 1;
                    }
                    if (num == 5)
                    {
                        ychecker5 += 1;
                    }
                    if (num == 6)
                    {
                        ychecker6 += 1;
                    }
                }
                int[] YValues = {ychecker1, ychecker2, ychecker3, ychecker4, ychecker5, ychecker6 };
                foreach (int number in YValues)
                {
                    if (number == 5)
                    {
                        go = 1;
                    }
                }
                if (go == 1)
                {
                    if (ycount >= 1)
                    {
                        scoreing += 100;
                        ycount++;
                        Session["YahtzeeCount"] = ycount;
                        ResetRoll();
                    }
                    if (ycount == 0)
                    {
                        ycount += 1;
                        Session["YahtzeeCount"] = ycount;
                        scoreing += 50;
                        ResetRoll();
                        RunningCount();
                    }
                }
                else
                {
                    if (ycount == 0)
                    {
                        scoreing += 0;
                        IBYahtzee.Attributes.Remove("src");
                        IBYahtzee.Attributes.Add("src", "../../Modules/Yahtzee/Images/yahtzeed.jpg");
                        IBYahtzee.Enabled = false;
                        ResetRoll();
                        RunningCount();
                    }
                    else
                    {
                        //ResetRoll();
                        LFeedback.Text = "Cheaters never prosper.";
                    }
                }
                Session["runningScore"] = scoreing;
                LScoreing.Text = scoreing.ToString();
            }
        }
    }
}